package com.kobe.game_20;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;

/**
 * 
 * Work out the first ten digits of the sum of the following one-hundred
 * 50-digit numbers.
 * 
 * The Diagram is shown in the direction of source!
 * 
 * 
 * the Result is: 5537376230
 * 
 * �ؼ��ǲ�Ҫ����ô����λ����ס������ȡ�ʵ����ȼ��ɡ�����ȡ12Ϊ��Ӻ�ȡ��10Ϊ��
 */
public class Game13 {

    public static void main(String[] args) throws IOException {
        LinkedList<String> words = getWords();
        String word = null;
        Long number = 0L;
        long result = 0L;
        for (int i = 0; i < 100; i++) {
            word = words.get(i);
            number = Long.valueOf(word.substring(0, 12));
            result = result + number;
        }

        System.out.println("the Result is: "
                + String.valueOf(result).substring(0, 10));
    }

    private static LinkedList<String> getWords() throws IOException {
        LinkedList<String> words = new LinkedList<String>();
        File file = new File("src/source/Game13_Numbers.txt");
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = null;
        while ((line = reader.readLine()) != null) {
            words.add(line);
        }
        return words;
    }
}
